﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using winS.UnityEditor.UIElement;

namespace winS.UnityEditor.ProcessEditor
{
    public sealed class NodeBorder : VisualElement
    {
        public const float borderOffset = -4f;
        public const float maxBorderMargin = 8f;
        public const float defaultBorderMargin = 1f;

        private static readonly List<TimeValue> transitionDurationList = new List<TimeValue>(4);
        private static readonly List<StylePropertyName> transitionPropertyList = new List<StylePropertyName>(4);

        static NodeBorder()
        {
            transitionDurationList.Add(0.2f);
            transitionDurationList.Add(0.2f);
            transitionDurationList.Add(0.2f);
            transitionDurationList.Add(0.2f);
            transitionPropertyList.Add("margin-top");
            transitionPropertyList.Add("margin-left");
            transitionPropertyList.Add("margin-right");
            transitionPropertyList.Add("margin-bottom");
        }

        public NodeBorder()
        {
            name = "节点边框";
            pickingMode = PickingMode.Ignore;
            style.SetMargin(defaultBorderMargin);
            style.SetBorder(Color.clear, 1f, StepNode.nodeBorderRadius);

            style.position = Position.Absolute;
            style.top = style.bottom = style.left = style.right = borderOffset;
        }

        public void PlayAnimation()
        {
            style.transitionProperty = null;
            style.transitionDuration = null;
            style.SetMargin(-maxBorderMargin);
            //style.transitionProperty = transitionPropertyList;
            //style.transitionDuration = transitionDurationList;
            style.SetMargin(defaultBorderMargin);
        }
    }
}